<#include "/WEB-INF/views/admin/common/layout/__formlayout.html">
<#assign pageCss>
<link rel="stylesheet" href="${ctx}/resource/validationengine/css/validationEngine.jquery.css">
<link rel="stylesheet" href="${ctx}/resource/tagit/css/tagit.ui-zendesk.css"/>
<link rel="stylesheet" href="${ctx}/resource/tagit/css/jquery.tagit.css"/>
</#assign>
<#assign pageScript>
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine.js"></script>
<script type="text/javascript" src="${ctx}/resource/tagit/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="${ctx}/resource/tagit/js/tag-it.js"></script>
<script type="text/javascript" src="${ctx}/resource/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="${ctx}/resource/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="${ctx}/resource/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    
	<#if blog.blog_type??>
		$("#blog_type").val(${blog.blog_type!});
	</#if>
	
	// ueditor
    var editor = UE.getEditor('container');
	
    $("#frm").validationEngine('attach', {
		promptPosition : 'topLeft',
		scroll : false
	});
	
    $.ajax({
   	  url: "${ctx}/admin/content/tags/tags_name",
   	  cache: false,
   	  success: function(json){
   		$('#tags').tagit({ 
   			//输入提示 
   			availableTags: json, 
   			// 与赋值操作有关 
   			singleField: true, 
   			allowSpaces: true, 
   			//标签中是否允许空格 
   			singleFieldNode: $('#fieldTags') //将值保存到mySingleField元素 
   		}); 
   	  }
   	});
	
	$("#subBtn").click(function() {
		var frm = $("#frm");
		if (frm.validationEngine("validate")) {
			var content = editor.getContent();
			if(content.length < 10){
				layer.alert("你写的内容太少了！",{icon:2});
				return;
			}
			$.ajax({
				type : "POST",
				url : "${ctx}/admin/content/blog/save_update",
				data : frm.serialize(),
				success : function(result) {
					if (result.isSuccess) {
						layer.msg(result.msg, {
							icon : 1,
							time : 1000,
							end : function() {
								//信息提示完成后关闭表单窗口
								var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
								parent.layer.close(index); //再执行关闭  
							}
						});
					} else {
						layer.msg(result.msg, {
							time : 1000,
							icon : 2
						});
					}
				}
			});
		}
	});
	
});
</script>
</#assign>
<@formlayout>
<div class="row">
	<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
		<div class="widget am-cf">
			<div class="widget-body am-fr">
				<form class="am-form tpl-form-border-form" id="frm" action="${ctx}/admin/blog/save_update">
					<input type="hidden" name="blog.id" value="${blog.id!}">
					<div class="am-form-group">
						<label for="title" class="am-u-sm-2 am-form-label">标题 </label>
						<div class="am-u-sm-10">
							<input type="text"
								class="tpl-form-input validate[required,maxSize[100]]" id="title" value="${blog.title!}"
								name="blog.title" placeholder="请输入标题">
						</div>
					</div>
					<div class="am-form-group">
						<label for="blog_type" class="am-u-sm-2 am-form-label">分类 </label>
						<div class="am-u-sm-10">
						<select name="blog.blog_type" class="am-selected-text validate[required]" id="blog_type">
					        <option value="0" >原创</option>
					        <option value="1" >收藏</option>
				      </select>
						</div>
					</div>
					<div class="am-form-group">
						<label for="fieldTags" class="am-u-sm-2 am-form-label">标签 </label>
						<div class="am-u-sm-7">
							<input type="hidden" name="tags" id="fieldTags" value="${tags}">
							<ul id="tags" class="am-selected-text"></ul>
						</div>
						<div class="am-u-sm-3">
							用逗号或空格分隔.
						</div>
					</div>

					<div class="am-form-group">
						<label for="share_url" class="am-u-sm-2 am-form-label">来源 </label>
						<div class="am-u-sm-10">
							<input type="text"
								class="tpl-form-input validate[maxSize[100],custom[url]]" id="share_url" value="${blog.share_url!}"
								name="blog.share_url" >
						</div>
					</div>

					<div class="am-form-group">
						<label for="des" class="am-u-sm-2 am-form-label">内容</label>
						<div class="am-u-sm-10">
							 <script id="container" name="blog.content" type="text/plain">
         						 ${blog.content!}
      						 </script>
						</div>
					</div>

					<div class="am-form-group">
						<div class="am-u-sm-9 am-u-sm-push-3">
							<button type="button"
								class="am-btn am-btn-primary tpl-btn-bg-color-success "
								id="subBtn">提交</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
</@formlayout>

